#include <iostream>
#include <string>
using namespace std;
int main()
{
	string be, en, type;
	int mile;
	int sum = 0;
	while(cin>>be)
	{
		if(be=="0")
		{
			cout << sum << endl;
			sum = 0;
			continue;
		}
		if (be == "#")
			return 0;
		cin >> en >> mile >> type;
		if (type == "F")
			sum = sum + mile * 2;
		if(type=="B")
		{
			sum += mile +static_cast<int>(mile / 2.0 + 0.5);
		}
		if(type=="Y")
		{
			if (mile >= 1 && mile <= 500)
				sum += 500;
			else
				sum += mile;
		}
		
	}
	return 0;
}